<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>享送小哥</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
</head>

<body>
    <div id="data-loading">
        <div class="loading1"><img src="../images/loading.gif"></div>
    </div>
    <div class="aui-content aui-margin-b-15 vue">
        <ul class="addr-list" v-if="address_list.length>0">

            <li v-for="item in address_list" style="position:relative;">
                <div class="addr-t1" style="padding-right:10%">{{item.province}}{{item.city}}{{item.district}}{{item.town}}{{item.address}}</div>
                <div class="addr-t2"><span class="aui-margin-r-10">{{item.name}}</span>{{item.phone}}</div>
                <div class="addr-icon addr-icon1" @click="del(item)" style="top:1rem;height:1rem;">
                    <img src="../images/addr2.png">
                </div>
            </li>

        </ul>
        <div v-if="address_list.length==0" style="text-align:center;margin-top:50px;color:#666;">没有地址使用记录!</div>
    </div>
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/vue.js"></script>
    <script type="text/javascript" src="../script/app.js"></script>
    <script type="text/javascript">
        apiready = function() {
            vObj = new Vue({
                el: ".vue",
                data: {
                    address_list: []
                },
                methods: {
                    getAddress: function() {
                        app.request.post('Client/address', {
                            type: api.pageParam.type
                        }, {}, function(res) {
                            if (res.code == 200) {
                                vObj.address_list = res.data;
                                app.request.finish(vObj);
                            } else {
                                app.error(res.message);
                            }
                        });
                    },
                    setDefault: function(address) {
                        app.request.post('Client/setDefaultAddress', {
                            address_id: address.id
                        }, {}, function(res) {
                            if (res.code == 200) {
                                vObj.getAddress();
                            } else {
                                app.error(res.message);
                            }
                        });
                    },
                    edit: function(address) {
                        app.page({
                            name: 'new_address',
                            url: 'new_address.html',
                            pageParam: {
                                address: address
                            }
                        })
                    },
                    del: function(address) {
                        api.confirm({
                            title: '提示',
                            msg: '确认删除吗?',
                            buttons: ['确定', '取消']
                        }, function(ret, err) {
                            if (ret.buttonIndex == 1) {
                                app.request.post('Client/delAddress', {
                                    address_id: address.id
                                }, {}, function(res) {
                                    if (res.code == 200) {
                                        vObj.getAddress();
                                    } else {
                                        app.error(res.message);
                                    }
                                });
                            }
                        });
                    }
                }
            })

            vObj.getAddress();

        }
    </script>
</body>

</html>
